<script setup>
import { ref, onMounted } from 'vue'
import { studentInfoService } from '@/api/student.js'

import StudentInfo from '@/views/student/components/StudentInfo.vue'
import CourseSelection from '@/views/student/components/CourseSelection.vue'
import MyCourse from '@/views/student/components/MyCourse.vue'
import { useUserStore } from '@/stores'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'
const router = useRouter()
const userStore = useUserStore()
//学生信息
const studentInfo = ref({
  name: '',
  gender: '',
  age: '',
  studentId: ''
})
// 获取学生信息
const getStudentInfo = async () => {
  const res = await studentInfoService(userStore.id)
  studentInfo.value.name = res.data.name
  studentInfo.value.gender = res.data.gender
  studentInfo.value.age = res.data.age
  studentInfo.value.studentId = res.data.studentId
}
onMounted(() => {
  getStudentInfo()
})
const logout = async () => {
  await ElMessageBox.confirm('你确认要进行退出么', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  userStore.removeToken()
  userStore.removeId()
  router.push('/login')
}

const activeTab = ref('info')
</script>

<template>
  <el-container>
    <el-header height="80">
      <el-row :gutter="20">
        <el-col :offset="10" :span="5">
          <h1>教务系统——学生信息页</h1>
        </el-col>
        <el-col :offset="6" :span="2">
          <el-button type="danger" @click="logout">退出登录</el-button>
        </el-col>
      </el-row>
    </el-header>
    <el-main>
      <div class="student-dashboard">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="个人信息" name="info">
            <StudentInfo :studentInfo="studentInfo" @getStudentInfo="getStudentInfo" />
          </el-tab-pane>
          <el-tab-pane label="自主选课" name="courses">
            <CourseSelection />
          </el-tab-pane>
          <el-tab-pane label="我的课表" name="my">
            <MyCourse />
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-main>
  </el-container>
</template>

<style scoped>
.el-container {
  padding: 20px 100px;
}

.status-form {
  margin-top: 20px;
}

.student-dashboard {
  padding: 20px;
}

.search-bar {
  margin: 20px 0;
  width: 400px;
}

.el-header {
  background-color: #B3C0D1;
  color: white;
  text-align: center;
  line-height: 60px;
  font-size: 20px;
}
</style>
